﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace EasyNet.Componets.Exceptions
{
    public class MultCustomException : CustomException
    {
        private List<CustomException> _errors;

        public MultCustomException(string errorCode, string message)
            : base(errorCode, message)
        {
            _errors = new List<CustomException>();
            this.Add(errorCode, message);
        }

        public IReadOnlyCollection<CustomException> Errors
        {
            get
            {
                _errors = _errors ?? new List<CustomException>();
                return _errors.AsReadOnly();
            }
        }

        public void Add(string errorCode, string message)
        {
            if (!string.IsNullOrEmpty(errorCode) && !string.IsNullOrEmpty(message))
            {
                var exception = new CustomException(errorCode, message);
                this.Add(exception);
            }

        }

        public void Add(CustomException exception)
        {
            if (exception != null)
            {
                _errors.Add(exception);
            }

        }

        public void AddRange(List<CustomException> exceptionList)
        {
            if (exceptionList != null && exceptionList.Count > 0)
            {
                _errors.AddRange(exceptionList);
            }
        }
    }
}
